package cn.swing.ushare.guestbook.webapi.controller;


import cn.swing.ushare.common.web.JsonResult;
import cn.swing.ushare.guestbook.service.IGuestbookService;
import cn.swing.ushare.pojo.vo.FeedBackVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping(value = "/guestbook", produces = "application/json;charset=utf-8")
public class GuestbookController {
    @Autowired
    private IGuestbookService service;

    @GetMapping("/delete-by-ids")
    @PreAuthorize("hasAnyAuthority('反馈删除')")
    public JsonResult<Void> deleteByIds(Integer[] ids) {
        System.out.println("feedBackVO = " + Arrays.deepToString(ids));
        service.deleteByIds(ids);
        return JsonResult.ok();
    }

    @GetMapping("/countAllGuestbook")
    public JsonResult<Integer> countAllGuestbook() {
        return JsonResult.ok(service.countAllGuestbook());
    }

    @RequestMapping("/list")
    public JsonResult<List<FeedBackVO>> list(Integer page, String feedbackPeople) {
        List<FeedBackVO> list = service.list((page - 1) * 10, feedbackPeople);
        return JsonResult.ok(list);
    }


    @RequestMapping("/count")
    public Integer count(String feedbackPeople) {
        return service.count(feedbackPeople);
    }


    @RequestMapping("/feedbackComment")
    public JsonResult<String> feedbackComment(String type, Integer commentId, Integer userId, String reason) {
        service.feedbackComment(type, commentId, userId, reason);
        return JsonResult.ok("反馈成功");
    }


    @RequestMapping("/feedbackArticle")
    public JsonResult<String> feedbackArticle(String type, String title, Integer userId, String reason) {
        service.feedbackArticle(type, title, userId, reason);
        return JsonResult.ok("反馈成功");
    }


}
